﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using ProductQR;

public partial class Student_bm_tj : System.Web.UI.Page
{
    DataClassesDataContext db1 = new DataClassesDataContext();
    private string wbh;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            stuInfo();
        }
        wbh = Session["wbh"].ToString();
        Label21.Text = wbh;
        if (wbh != null)
        {
            QR qr = new QR();
            Bitmap bm = qr.BarcodeImage(Session["wbh"].ToString().Trim());
            string filename = Session["wbh"].ToString();
            bm.Save(Server.MapPath("~/QR/") + filename + ".jpg");//存到自己的QR文件夹下，QR只是个文件夹名,jpg,png都可以
            this.Image3.ImageUrl = "~/QR/" + filename + ".jpg";//然后再用image控件引入上
        }
    }
    private void stuInfo()
    {
        wbh = Session["wbh"].ToString();
        var resNation = from p in db1.proc_GetNation()
                        select p;
        var resPolitics = from p in db1.proc_GetPolitics()
                          select p;
        var result = (from p in db1.proc_GetStuInfoBywbh(wbh)
                      select p).ToList().First();
        var year = (from p in db1.proc_GetBkgxNowYear()
                      select p).ToList().First();
        Label22.Text=year.dYear;
        Image2.ImageUrl = "~/Student/stuimage/" + result.sidfy + ".jpg";
        Label3.Text = result.sname;
        Label4.Text = result.ssex;
        Label5.Text = result.snation;
        Label6.Text = result.sps;
        string S = result.sbirth;
        if (S != null)
            Label7.Text = S.Substring(0, 4) + "年" + S.Substring(4, 2) + "月" + S.Substring(6, 2) + "日";
        Label8.Text = result.sidfy;
        Label9.Text = result.gkbmh;
        Label10.Text = result.sdept;
        Label11.Text = result.byzy;
        Label12.Text = result.bkgx;
        Label13.Text = result.proName;
        Label14.Text = result.proNum;
        TextBox1.Text = result.getaward;
        TextBox2.Text = result.advantage;
        Label15.Text = result.haddress;
        Label16.Text = result.sphone;
        Label17.Text = result.lxaddress;
        Label18.Text = result.postcode;
        int flag = Convert.ToInt32(result.proflag);
        if (flag == 1)
        {
            pl_submit.Visible = true;
            pl_Print.Visible = false;
        }
        else
        {
            if (flag > 1)
            {
                pl_submit.Visible = false;
                pl_Print.Visible = true;
            }
        }
    }
    protected void bt_submit_Click(object sender, EventArgs e)
    {
        wbh = Session["wbh"].ToString();
        if ((db1.proc_UpdateStuProFlagBywbh(wbh, 2)) == -1)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "success", "<script>alert('操作失败，请重试！');</script>");
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "success", "<script>alert('提交成功！');</script>");
            pl_submit.Visible = false;
            pl_Print.Visible = true;
        }
    }
}